package main

import (
	"flag"
	"fmt"
	"time"
	"github.com/spf13/pflag"
	"io/ioutil"
	"os/exec"
)

//var wine_path ="ls"
var exe_path="."
func main()  {

//	pflag.StringVar(&wine_path,"wine-path",wine_path,"wine path")
	pflag.StringVar(&exe_path,"exe-path",exe_path,"exe path")
	pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
	pflag.Parse()


	files, _ := ioutil.ReadDir(exe_path)
	for _, f := range files {
		command:=`
ps -ef | grep button_exe | awk '{print "kill -9 "$2}' | bash
ps -ef | grep wine | awk '{print "kill -9 "$2}' | bash
`
		fileName:=f.Name()
		fmt.Println(fileName)

		if len(fileName)>=4 && fileName[(len(fileName)-4):]==".exe"{
			fmt.Println(f.Name())
			command=fmt.Sprintf("%s",command)
			fmt.Println(command)
			cmd := exec.Command("/bin/bash", "-c", command)
			err:=cmd.Start()
			if err!=nil{
				fmt.Printf("%v",err)
			}
                        time.Sleep(5*time.Second)

			cmd = exec.Command("wine", fmt.Sprintf("%s/%s",exe_path,fileName))
			err=cmd.Run()
			if err!=nil{
				fmt.Printf("%v",err)
			}

		}
	}

}
